package de.fuberlin.inf.alp2.utils;

public class Quicksort {
	private static void qsort(double field[],int left,int right) {
		int l = left;
		int r = right;
		double p = field[(l+r)/2];

		do {
			while (field[l] < p)
				l++;
			while (field[r] > p)
				r--;
			if (l <= r) {
				if (l < r) {
					double tmp = field[l];
					field[l] = field[r];
					field[r] = tmp;
				}
				l++;r--;
			}
		} while (l <= r);
		
		if (left < r)
			qsort(field, left, r);
		if (l < right)
			qsort(field, l, right);
	}

	public static void sort(double a[]) {
		qsort(a, 0, a.length-1);
	}
}